<?php
class Utility 
{
	public static function error_msg ($message)
	{
		$message = str_replace("'", "\'", $message);
		echo "<script>alert('$message');window.history.go(-1);</script>";
		exit;
	}

	public static function format_time($create_time)
	{
	       if(time()-$create_time<86400){
					        $create_time = time()-$create_time;
							if(($create_time/3600)>1){
							     $create_time = floor($create_time/3600).'小时前';
							}else{
							    if(($create_time/60)>1)
								$create_time = floor($create_time/60).'分钟前';
								else
								$create_time = $create_time.'秒前';
							} 
					 }else{
					       $create_time = date('Y-m-d H:i',$create_time);
					 }
			return $create_time;		 
	}

    public static function post_data ($url, $data, $return_transfer = FALSE)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_transfer);
        curl_setopt($ch, CURLOPT_POST, TRUE);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
    }

    public static function get_data ($url, $return_transfer = TRUE)
    {
		$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_transfer);
		$server_output = curl_exec ($ch);
		curl_close ($ch);		

        return $server_output;
    }

    public static function make36($t10) 
    {
        if ($t10 == '')
            return '';

        $tt = $t10 . "";
        $result = "";
        $a = (int) ($t10 / 36);
        $b = $t10 % 36;
        $result .= self::int2c($b);


        while ($a > 0) 
        {
            $m = $a;
            $a = (int) ($m / 36);
            $b = $m % 36;
            $result .= self::int2c($b);
        }


        $x = '';
        for ( $i = strlen($result) - 1; $i >= 0; $i--)
        {
            $x .= $result[$i];
        }

        return $x;
    }

    private static function int2c($b) 
    {
        if ($b < 10)
            return $b + "";
        else 
        {
            $n = 65 - 10 + $b;
            $c = $n;
            return chr($c);
        }
    }

}
